<template>
  <div class="box">
    <div class="boxLogin">
      <div class="chanes">
        <!-- <img src="../../assets/img/cn.png" /> -->
      </div>
      <span class="locale">{{this.$i18n.locale}}</span>
      <div class="logo">
        <img src="../../assets/img/logo.png" />
      </div>
      <div class="userPass">
        <el-form
          :model="ruleForm"
          status-icon
          :rules="rules"
          ref="ruleForm"
          class="demo-ruleForm"
        >
          <el-form-item prop="account">
            <div>{{ $t("lang.account") }}:</div>
            <el-input
              v-model.number="ruleForm.account"
              :style="{ width: '320px' }"
              style="margin-top: -15px"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password" show-password>
            <div style="margin-top: -15px">{{ $t("lang.password") }}:</div>
            <el-input
              type="password"
              v-model="ruleForm.password"
              autocomplete="off"
              :style="{ width: '320px' }"
            ></el-input>
          </el-form-item>
          <!-- 忘记密码 -->
          <div class="pass">
            <span
              ><router-link to="">{{
                $t("lang.forgetPassword")
              }}</router-link></span
            >
          </div>
          <!-- 滑块 -->
          <div class="slider">
            <span class="sliderTxt">{{ $t("lang.sliderCheck") }}:</span>
            <slider
              status="ruleForm.status"
            ></slider>
          </div>
          <el-button
            type="primary"
            @click="submitForm('ruleForm')"
            :style="{
              width: '320px',
              height: '40px',
              marginTop: '10px',
              fontSize: '16px',
            }"
            >{{ $t("lang.login") }}</el-button
          >
        </el-form>
        <el-row>
          <el-button
            type="primary"
            plain
            :style="{ width: '320px', marginTop: '20px', height: '40px' }"
            >{{ $t("lang.register") }}</el-button
          >
        </el-row>
      </div>
    </div>
    <!-- 尾部 -->
    <div class="foolter">
      <div class="fool floterImg">
        <img src="../../assets/img/seeed.png" />
      </div>
      <div class="fool copy">
        <span>©2008-2021 {{ $t("lang.compony") }}</span>
        <span>粤|CP备13058720号</span>
      </div>
      <div class="fool Privacy">{{ $t("lang.privacy") }}</div>
      <div class="fool floterImg2">
        <img src="../../assets/img/mcafee.png" />
      </div>
      <div class="fool">
        <el-select
          v-model="lang"
          placeholder="$('locale.lang')"
          @change="changLang"
          size="small"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
    </div>
  </div>
</template>

<script>
// 引入滑块组件
import Slider from "@/components/Slider.vue";
export default {
  name: "login",
  components: {
    Slider,
  },
  data() {
    return {
      ruleForm: {
        account: "",
        password: "",
      },
      rules: {
        account: [{ required: true, trigger: "blur", message: "请输入账号!" }],
        password: [{ required: true, trigger: "blur", message: "请输入密码!" }],
        status: [
          { required: true, trigger: "change", message: "请拖动滑块完成验证!" },
        ],
      },
      options: [
        {
          value: "zh",
          label: this.$t("lang.cs"),
        },
        {
          value: "en",
          label: this.$t("lang.is"),
        },
      ],
      lang: "",
    };
  },
  methods: {
    // 登录
    submitForm() {
      console.log("登录了!");
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // 验证成功
          // 调用vue中user子树里面的 登录的 action动作
          this.$store.dispatch("LoginAction", this.ruleForm);
        } else {
          console.log("验证没通过!");
        }
      });
    },
    // 切换语言
    changLang() {
      console.log("语言集触发啦");
      console.log(this.$i18n.locale);
      // this.$i18n.locale = "zh";
      this.$store.commit("SET_LANG", this.lang);
      // 整个页面刷新
      this.$router.go(0);
    },
    // var checkStatus =  (rule,value,callback) =>{
    //   console.log(value);
    //   if(!value){
    //     return callback(new Error('请拖动滑块完成验证'));
    //   }else{
    //     callback();
    //   }
    // }
  },
  created() {
    console.log(this);
    this.lang = this.$store.getters.locale;
  },
};
</script>

<style scoped lang="scss">
.box {
  width: 100%;
  height: 100vh;
  background: #e8e8e8;
  .boxLogin {
    background: #fff;
    width: 400px;
    // height: 470px;
    padding-bottom: 10px;
    border: 1px solid #e8e8e8;
    margin: 0 auto;
    position: relative;
    top: 10%;
    .chanes {
      // width: 50px;
      // height: 50px;
      float: right;
      // border: 1px solid #000;
      border-style: solid;
      border-width: 60px 60px 0px 0px;
      border-color: blue transparent transparent transparent;
      transform: rotate(90deg);
      width: 0px;
      height: 0px;
      position: relative;
    }
    .locale{
        position: absolute;  
        right:7px;
        color:#fff;
        line-height: 40px;
        // font-size: 16px;
        font-weight: bold;
      }
    .logo {
      width: 100%;
      height: 60px;
      display: flex;
      justify-content: space-around;
      margin-top: 30px;
      align-items: center;
      img {
        width: 180px;
      }
    }
    .userPass {
      // margin-top: 20px;
      display: flex;
      justify-content: space-between;
      flex-direction: column;
      align-items: center;
      .pass {
        width: 80px;
        height: 30px;
        font-size: 14px;
        margin-top: -20px;
        margin-left: 240px;
        a {
          color: #222;
        }
      }
      .slider {
        width: 320px;
        height: 70px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .sliderTxt {
          font-weight: 700;
        }
      }
    }
  }
  .foolter {
    width: 100%;
    height: 60px;
    background: #fff;
    position: fixed;
    bottom: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    .fool {
      margin-left: 50px;
    }
    .floterImg {
      width: 120px;
      img {
        width: 100%;
      }
    }
    .floterImg2 {
      width: 70px;
      img {
        width: 100%;
      }
    }
    .copy {
      display: flex;
      flex-direction: column;
      font-size: 13px;
    }
    .Privacy {
      display: flex;
      flex-direction: row;
      width: 100px;
      font-size: 13px;
      align-items: center;
    }
  }
}
</style>